package com.sg.hms.controller;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.crypto.Data;

import com.sg.hms.Model.Getpath;
import com.sg.hms.Model.User;
import com.sg.hms.Service.RoomService;
import com.sg.hms.ServiceImpl.RoomServiceImpl;
/***
 * 删除房间物品
 * @author 吴磊
 *
 */
public class DeleteRoomEquiptmentController extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String [] rid=req.getParameterValues("rid");
		String [] eid=req.getParameterValues("eid");
		RoomService room=new RoomServiceImpl();
		User user=(User) req.getSession().getAttribute("currentuser");
		int id=user.getuId();
		String fpath=Getpath.getpath1();
		StringBuffer stringBuffer=new StringBuffer(fpath+"/Delete");
		stringBuffer.append(String.valueOf(id));
		Date date=new Date();
		SimpleDateFormat sim=new SimpleDateFormat("yyyyMMddHHmmss");
		String now=sim.format(date);
		stringBuffer.append(now);
		stringBuffer.append(".txt");
		String path=stringBuffer.toString();
		File file=new File(path);
		file.createNewFile();
		FileWriter writer=new FileWriter(file, true);
		String s1="删除的房间编号：";
		for (int i = 0; i < rid.length; i++) {
			s1=s1+rid[i];
		}
		String s2="删除的物品编号：";
		for (int i = 0; i < eid.length; i++) {
			s2=s2+eid[i];
			
		}
		writer.write(s1);
		writer.write("\r\n");
		writer.write(s2);
		writer.flush();
		writer.close();
		room.DeleteRoom(rid, eid);
	}

}
